Safely Rolling Back Transactions In A Transactional Memory System With Concurrent Readers

ABSTRACT

A technique for safely rolling back transactional memory transactions without impacting concurrent readers of the uncommitted transaction data. An updater uses a transactional memory technique to perform an data update on data that is shared with a reader. The update is implemented as a transaction in which the updated data is initially uncommitted due to the transaction being subject to roll back. The reader is allowed to perform a data read on the uncommitted data during the transaction. Upon a rollback of the transaction, reclamation of memory locations used by the uncommitted data is deferred until a grace period has elapsed after which the reader can no longer be referencing the uncommitted data.

BACKGROUND

1. Field of the Invention

The present invention relates to computer systems and methods in which data resources are shared among concurrent data consumers while preserving data integrity and consistency relative to each consumer. More particularly, the invention concerns a concurrency implementation wherein a transactional memory system operates in conjunction with a mutual exclusion mechanism known as “read-copy update.”

2. Description of the Prior Art

By way of background, transactional memory (TM) and read-copy update (RCU) both provide techniques for concurrent programming, each with various advantages and disadvantages. A single programming system may want to support both techniques. In particular, the system may want to use TM transactions to modify data while RCU readers read the same data. A combination of these two techniques could choose to present many different semantics. For some algorithms, an RCU reader can cope with uncommitted data (data that a transaction has written but not yet committed). However, previous work on combining transactions and RCU readers has required that an RCU reader may only see uncommitted data once the transaction has reached a point where it must commit, and cannot fail and roll back. Otherwise, rolling back a transaction may free memory allocated during the transaction, and thus cause the RCU reader to access an object that no longer exists, generating a fault or a difficult-to-detect error. The present invention allows readers to access uncommitted data that may disappear when a transaction rolls back.

SUMMARY

A technique for safely rolling back transactional memory transactions without impacting concurrent readers of uncommitted transaction data. An updater uses a transactional memory technique to perform an data update on data that is shared with a reader. The update is implemented as a transaction in which the updated data is initially uncommitted due to the transaction being subject to roll back. The reader is allowed to perform a data read on the uncommitted data during the transaction. Upon a rollback of the transaction, reclamation of memory locations used by the uncommitted data is deferred until a grace period has elapsed after which the reader can no longer be referencing the uncommitted data.

BRIEF DESCRIPTION OF THE DRAWINGS

The foregoing and other features and advantages of the invention will be apparent from the following more particular description of example embodiments, as illustrated in the accompanying Drawings, in which:

FIG. 1 is a functional block diagram showing an example computing system that implements data readers, data updaters, a TM subsystem, and an RCU subsystem;

FIG. 2 is a functional block diagram showing example components of the TM subsystem of FIG. 1;

FIG. 3 is a functional block diagram showing example components of the RCU subsystem of FIG. 1;

FIG. 4 is a functional block diagram showing example components of a rollback component in the TM subsystem of FIG. 1 according to one embodiment;

FIG. 5 is a functional block diagram showing example components of a rollback component in the TM subsystem of FIG. 1 according to another embodiment;

FIG. 6 is a flow diagram showing example operations of the TM subsystem of FIG. 1;

FIG. 6A is a flow diagram showing a modification of the flow diagram of FIG. 6; and

FIG. 7 is a diagrammatic illustration of example media that may be used to provide a computer program product for implementing TM modifications and RCU readers in accordance with the present disclosure.

DETAILED DESCRIPTION OF EXAMPLE EMBODIMENT

Turning now to the figures, wherein like reference numerals are used to represent like elements in all of the several views, FIG. 1 illustrates an example computing environment in which the disclosed embodiment may be implemented. In particular, an example computing system 2 is shown in which one or more processors 4 (e.g., 4 ₁, 4 ₂ . . . 4 _(n)) are connected by way of a system bus 6 to a memory 8. As used herein, “processors” refers to single-threaded or multi-threaded CPUs (Central Processing Units) within single-core or multi-core processing devices (each core being considered a CPU) that execute program instruction logic, such as software or firmware. Such processing devices may be used in general purpose computers, special purpose computers, portable computing devices, communication and/or media player devices, set-top devices, embedded systems, to name but a few. The memory 8 may comprise any type of tangible storage medium capable of storing data in computer readable form. The processors 4 and the memory 8 may be situated within a single computing node (e.g., as part of a single-node SMP system) or they may be distributed over plural nodes (e.g., as part of a NUMA system or cluster). Conventional cache memories 10 (e.g., 10 ₁, 10 ₂ . . . 10 _(n)) and cache controllers 12 (e.g., 12 ₁, 12 ₂ . . . 12 _(n)) may be respectively associated with the processors 4. A conventional memory controller 14 may be associated with the memory 8. The memory controller 14 may be integrated with the processors 4 or could be provided separately therefrom (e.g. as part of a chipset).

It is assumed in FIG. 1 that update operations executed within user-level or operating system-level tasks (e.g., processes, threads or other execution contexts) will periodically perform updates on shared data 16 stored in the memory 8. Reference numeral 18 (e.g., 18 ₁, 18 ₂ . . . 18 _(n)) is used to represent individual update operations (updaters) that may periodically execute on the processors 4 from program instructions stored in the memory 8. The updates performed by the updaters 18 may include modifying elements of a linked list, inserting new elements into the list, deleting elements from the list, and many other types of operations (involving lists or other data structures). The processor 4 also periodically executes user-level or operating system-level read operations (readers) 20 (e.g., 20 ₁, 20 ₂ . . . 20 _(n)) from program instructions stored in the memory 8. The readers are assumed to reference the shared data 16 for reading without using locks or other mutual exclusion techniques.

The updaters 18 are assumed to periodically perform updates to the shared data 16 using a Transactional Memory (TM) subsystem 22 that operates in the computing system 2. The TM subsystem 22 implements updates to the shared data 16 as serialized transactions that tend to be atomic, consistent, isolated, and to some extent durable. Each transaction either completes successfully without conflict with other transactions, in which case the transaction is committed, or it does not complete, in which case the transaction is aborted and rolled back. Roll back is performing by reverting the transaction state changes and reclaiming the memory locations used to hold uncommitted data written during the transaction. Except as modified in accordance with the present disclosure, the TM subsystem 22 may be implemented in any suitable manner using known transactional memory techniques that may be hardware-based, software-based, or some combination of both.

Turning now to FIG. 2, the TM subsystem 22 may include several functional components, including but not limited to an updater interface component 24, a transaction processing component 26, and a rollback component 28. The updater interface component 24 may be used by the updaters 18 (and other code) to interact with the TM subsystem 22. For example, the updater interface component 24 may provide primitives that can be used to delimit transaction start and stop points, restart transactions, interrupt and restore transactions, etc.

The transaction processing component 26 may be used to implement the load and store instructions that operate on a transaction's read and write sets. As persons skilled in the art will appreciate, a transaction's read set and write set respectively represent the shared memory values that have been read and written during a transaction. The transaction processing component 26 may also be used to manage transaction state as a transaction proceeds to the point where it either commits or fails. A transaction will typically commit only if no other transaction has updated any location in the transaction's read or write set, and no other transaction has read any location in the transaction's write set. To make this determination, the transaction processing component 26 implements a suitable form of conflict detection. When a transaction commits, the transaction's changes to its write set become finalized. If the commit fails, the transaction aborts. A transaction abort causes all changes to the transaction's write set (i.e., the uncommitted transaction data) to be discarded. This is known as a roll back.

The rollback component 28 manages transaction rollback and the reclamation of memory associated with uncommitted transaction data following a transaction abort. In the prior art, the reclamation of memory occurs without regard to other tasks. However, as will be described in more detail below, the present disclosure presents an alternative technique wherein the rollback component 28 implements reclamation in a manner that allows the readers 20 to access uncommitted data concurrently during transaction processing.

The readers 20 may be implemented as tasks that access the shared data 16 using a Read-Copy Update (RCU) subsystem 30. The RCU subsystem 30 comprises RCU subsystem instances 30 ₁, 30 ₂ . . . 30_(n). that periodically execute on the processors 4 from program instructions stored in the memory 8. RCU is a synchronization technique that permits shared data to be accessed for reading without the use of locks, writes to shared memory, memory barriers, atomic instructions, or other computationally expensive synchronization mechanisms, while still permitting the data to be updated (modify, delete, insert, etc.) concurrently. The read-copy update technique implements data updates in two phases. In the first (initial update) phase, the actual data update is carried out in a manner that temporarily preserves two views of the data being updated. One view is the old (pre-update) data state that is maintained for the benefit of operations that may be currently referencing the data. The other view is the new (post-update) data state that is available for the benefit of operations that access the data following the update. In the second (deferred update) phase, the old data state is removed following a “grace period” that is long enough to ensure that all executing operations will no longer maintain references to the pre-update data. In the context of the read-copy update mechanism, a grace period represents the point at which all running tasks (e.g., processes, threads, or other execution contexts) having access to an RCU-protected data element have passed through a “quiescent state” after which they can no longer maintain references to the data element, assert locks thereon, or make any assumptions about data element state. By convention, for operating system kernel code paths, a context switch, an idle loop, and user mode execution all represent quiescent states for any given CPU (as can other operations that will not be listed here). The second-phase update operation typically comprises freeing a stale data element from memory.

Turning now to FIG. 3, the RCU subsystem 30 may include a reader interface component 32, an updater interface component 34, and a deferred reclamation component 36. The reader interface component 32 may be implemented using primitives such as rcu_read_lock( ) and rcu_read_unlock( ). These primitives may be invoked by the readers 20 when they respectively enter and leave an RCU-protected critical section. Such primitives provide a way for the readers 20 to advise the RCU subsystem 30 that they are engaged in RCU-protected critical section processing. The RCU subsystem 30 can use this information to track reader quiescent states as part of grace period detection. In particular, any reader 20 that is not executing critical section code nested by rcu_read_lock( ) and rcu_read_unlock( ) may be deemed to be quiescent. Alternatively, RCU may be implemented without use of such primitives, in which case reader quiescent states may be detected in other ways, such as by forcing a quiescent state using inter-processor interrupts to initiate task rescheduling.

The updater interface component 34 may be implemented using a primitive such as call_rcu( ). This primitive may be invoked by an updater 18 when it has performed an update on the shared data 16 in order to register a callback for deferred destruction of a stale pre-update version of the data. Another RCU primitive known as synchronize_rcu( ) allows an updater 18 to request a grace period, then block until the grace period has elapsed, and then remove the stale data itself.

The deferred reclamation component 36 may be implemented using any of the known RCU techniques for tracking grace periods and performing deferred reclamation of stale data elements. For example, the deferred reclamation component 36 could batch generations of callbacks on callback lists. As each grace period elapses, a new batch of callbacks that are ripe for processing can be executed, thereby reclaiming the memory locations that hold the data associated with the callbacks.

Returning now to FIG. 2, transactional memory is typically implemented in such a way that a transaction's write set does not become visible to other tasks until the transaction must commit. However, as described in the Background section above, there may be implementations where is it desirable to allow readers to reference uncommitted data (without necessarily forcing a roll back due to a reader accessing the transaction's write set). This need could arise in an environment such as the computing system 2 that supports both the TM and RCU data synchronization techniques. The same need could also arise with respect to readers that reference shared data without the use RCU.

The TM subsystem 22 is therefore designed to support concurrent reader access to uncommitted transactional memory data. In particular, the rollback component 28 is designed to have the capability of implementing deferred reclamation of uncommitted data following a transaction abort. When a transaction rolls back, instead of immediately reclaiming the memory allocated to the uncommitted transaction data, the rollback component 28 may use an RCU (or other) deferred reclamation mechanism to defer freeing this memory until a grace period has elapsed due to all affected readers having passed through a quiescent state. This ensures that no reader can pick up a pointer to an uncommitted transaction data object that disappears before the reader completes. The transaction processing component 26 may also be modified to allow reader access to transaction write set data without triggering a roll back. However, there may be implementations where this modification is not desired, such that readers accessing uncommitted data will in fact cause a transaction to a roll back.

The foregoing functionality may be implemented according to different embodiments. FIG. 4 illustrates a first example embodiment wherein the rollback component 28 incorporates a native deferred reclamation component 28A. The native reclamation component 28A could be implemented using any of the existing RCU deferred reclamation techniques (or other present or future reclamation techniques) in order to detect the end of grace period signifying all of the readers 20 have passed through a quiescent state and can no longer be referencing uncommitted transaction data. FIG. 5 illustrates a second example wherein the rollback component 28 includes a reclamation stub component 28B that is programmed to utilize the deferred reclamation component 36 of the RCU subsystem 30. In this embodiment, the TM subsystem 22 could act like a regular RCU updater that registers callbacks to be processed following the end of a grace period via the updater interface 34. The reclamation component 36 of the RCU subsystem 30 would then track reader quiescent states in the usual manner to detect the end of a grace period.

Turning now to FIG. 6, example operations of the TM subsystem 22 are shown for supporting concurrent reader access to uncommitted transaction data according to the foregoing embodiments. In block 40, the transaction processing component 26 initiates a transactional memory transaction while permitting the readers 20 to concurrently read uncommitted transaction data prior to commit. In block 42, the transaction is run until it either aborts or commits. In block 44, if the transaction aborted, processing proceeds to block 46. In block 46, the rollback component 28 either performs deferred reclamation of the memory locations associated with uncommitted transaction data using the native deferred reclamation component 28A, or using the reclamation stub 28B to request such processing. If it is determined in block 44 that the transaction did not abort, block 46 is bypassed. However, it should be pointed out that there may be implementations where it is desired to perform deferred memory reclamation following a commit, such as to reclaim memory that a transaction removed from a data structure. FIG. 6A, which is identical to FIG. 6 except for the addition of new block 48, illustrates this alternative. Block 48 serves to invoke block 46 to perform deferred memory reclamation if it is determined that there was a transaction commit that resulted in data removal. In this way, readers that may have been concurrently referencing the data structure can be protected from premature reclamation of the removed data until a grace period has elapsed.

Accordingly, a technique has been disclosed for safely rolling back transactional memory transactions with concurrent readers accessing uncommitted data. It will be appreciated that the foregoing concepts may be variously embodied in any of a data processing system, a machine implemented method, and a computer program product in which digitally encoded program instructions are stored on one or more computer-readable data storage media for use in controlling a computer or other data processing machine to perform the required functions. The program instructions may be comprise machine language code that is ready for loading and execution by the machine apparatus, or the program instructions may comprise a higher level language that can be assembled, compiled or interpreted into machine language. Example high level languages include, but are not limited to assembly, C, C++, to name but a few. When implemented on a machine comprising a CPU, the program instructions combine with the CPU to provide a particular machine that operates analogously to specific logic circuits, which themselves could be used for the invention.

Example data storage media for storing such program instructions are shown by reference numeral 100 in FIG. 7. The media 100 are shown as being portable optical storage disks of the type that are conventionally used for commercial software sales, such as compact disk-read only memory (CD-ROM) disks, compact disk-read/write (CD-R/W) disks, and digital versatile disks (DVDs). Such media can store the program instructions of the invention either alone or in conjunction with an operating system or other software product that incorporates the required functionality. The media could also be provided by portable magnetic media (such as floppy disks, flash memory sticks, etc.), or magnetic media combined with drive systems (e.g. disk drives), or media incorporated in data processing platforms, such as random access memory (RAM), read-only memory (ROM) or other semiconductor or solid state memory. More broadly, the media could comprise any electronic, magnetic, optical, infrared, semiconductor system or apparatus or device, or any other tangible entity representing a machine, manufacture or composition of matter that can contain, store, communicate, or transport the program instructions for use by or in connection with an instruction execution system, apparatus or device, such as a computer. For all of the above forms of media, when the program instructions are loaded into and executed by an instruction execution system, apparatus or device, the resultant programmed system, apparatus or device becomes a particular machine for practicing embodiments of the method(s) and system(s) described herein.

Although various embodiments of the invention have been described, it should be apparent that many variations and alternative embodiments could be implemented in accordance with the invention. It is understood, therefore, that the invention is not to be in any way limited except in accordance with the spirit of the appended claims and their equivalents. 

What is claimed is:
 1. In a data processing system having at least one CPU, a memory operatively coupled to said CPU, said memory including a storage medium tangibly embodying data that is subject to concurrent access by a data updater that updates said data and a data reader that reads said data, a method for safely rolling back transactions implemented by said updater to update said data using a transactional memory technique as said reader reads said updated data while said transactions are uncommitted and subject to roll back, comprising: said updater executing on said at least one CPU to perform a data update on said data to produce updated data using a transactional memory technique wherein said data update is implemented as a transaction in which said updated data is initially uncommitted data due to said transaction being subject to roll back; said reader executing on said at least one CPU to perform a data read on said uncommitted data; and upon a rollback of said transaction, deferring reclamation of memory locations used by said uncommitted data until a grace period has elapsed after which said reader can no longer be referencing said uncommitted data.
 2. The method of claim 1, further including: upon a commit of said transaction, deferring reclamation of memory locations used by data that has been removed by said transaction until a grace period has elapsed after which said reader can no longer be referencing said removed data.
 3. The method of claim 1, wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that performs said rollback using an internal deferred reclamation mechanism that is part of said transactional memory subsystem.
 4. The method of claim 3, wherein said deferred reclamation of said uncommitted data is performed using a read-copy update deferred reclamation technique.
 5. The method of claim 1, wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that calls an external deferred reclamation mechanism that is part of a read-copy update subsystem.
 6. The method of claim 1, wherein said reader is a read-copy update reader that uses read-copy update primitives to read said uncommitted data.
 7. A system, comprising: a CPU; a memory operatively coupled to said CPU, said memory including a storage medium tangibly embodying data that is subject to concurrent access by a data updater that updates said data and a data reader that reads said data; said memory further tangibly embodying a program of instructions executable by said CPU to perform operations for safely rolling back transactions implemented by said updater to update said data using a transactional memory technique as said reader reads said updated data while said transactions are uncommitted and subject to roll back, comprising: said updater executing on said at least one CPU to perform a data update on said data to produce updated data using a transactional memory technique wherein said data update is implemented as a transaction in which said updated data is initially uncommitted data due to said transaction being subject to roll back; said reader executing on said at least one CPU to perform a data read on said uncommitted data; and upon a rollback of said transaction, deferring reclamation of memory locations used by said uncommitted data until a grace period has elapsed after which said reader can no longer be referencing said uncommitted data.
 8. The system of claim 7, wherein said operations further include: upon a commit of said transaction, deferring reclamation of memory locations used by data that has been removed by said transaction until a grace period has elapsed after which said reader can no longer be referencing said removed data.
 9. The system of claim 7, wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that performs said rollback using an internal deferred reclamation mechanism that is part of said transactional memory subsystem.
 10. The system of claim 9, wherein said deferred reclamation of said uncommitted data is performed using a read-copy update deferred reclamation technique.
 11. The method of claim 7, wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that calls an external deferred reclamation mechanism that is part of a read-copy update subsystem.
 12. The system of claim 7, wherein said reader is a read-copy update reader that uses read-copy update primitives to read said uncommitted data.
 13. A computer program product, comprising: one or more computer-readable media: program instructions stored on said one or more media for programming a CPU that is operatively coupled to a memory, said memory including a storage medium tangibly embodying data that is subject to concurrent access by a data updater that updates said data and a data reader that reads said data, said program instructions programming said CPU to perform operations, comprising: said updater executing on said at least one CPU to perform a data update on said data to produce updated data using a transactional memory technique wherein said data update is implemented as a transaction in which said updated data is initially uncommitted data due to said transaction being subject to roll back; said reader executing on said at least one CPU to perform a data read on said uncommitted data; and upon a rollback of said transaction, deferring reclamation of memory locations used by said uncommitted data until a grace period has elapsed after which said reader can no longer be referencing said uncommitted data.
 14. The computer program product of claim 13, wherein said operations further include: upon a commit of said transaction, deferring reclamation of memory locations used by data that has been removed by said transaction until a grace period has elapsed after which said reader can no longer be referencing said removed data.
 15. The computer program product of claim 13, wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that performs said rollback using an internal deferred reclamation mechanism that is part of said transactional memory subsystem.
 16. The computer program product of claim 15, wherein said deferred reclamation of said uncommitted data is performed using a read-copy update deferred reclamation technique.
 17. The computer program product of claim 13, wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that calls an external deferred reclamation mechanism that is part of a read-copy update subsystem.
 18. The computer program product of claim 13, wherein said reader is a read-copy update reader that uses read-copy update primitives to read said uncommitted data.
 19. In a data processing system having at least one CPU, a memory operatively coupled to said CPU that includes a storage medium tangibly embodying data that is subject to concurrent access by a data updater that updates said data and a data reader that reads said data, a method for safely rolling back transactions implemented by said updater to update said data using a transactional memory technique as said reader reads said updated data while said transactions are uncommitted and subject to roll back, comprising: said updater executing on said at least one CPU to perform a data update on said data to produce updated data using a transactional memory technique wherein said data update is implemented as a transaction in which said updated data is initially uncommitted data due to said transaction being subject to roll back; said transactional memory technique being one of a hardware transactional memory technique or a software transactional memory technique. said reader executing on said at least one CPU to perform a data read on said uncommitted data; said reader being a read-copy update reader that uses read-copy update primitives to read said uncommitted data; and upon a rollback of said transaction, deferring reclamation of memory locations used by said uncommitted data until a grace period has elapsed after which said reader can no longer be referencing said uncommitted data; and said deferred reclamation of memory locations used by said uncommitted data is performed using a read-copy update deferred reclamation technique.
 20. The method of claim 19 wherein said deferred reclamation of said uncommitted data is performed using a transactional memory subsystem that either (1) performs said rollback using an internal read-copy update deferred reclamation mechanism that is part of said transactional memory subsystem, or (2) calls an external read-copy update deferred reclamation mechanism that is part of a read-copy update subsystem. 